* This file replicates the empirical analysis presented in "Designing Alliances: How Adversaries Provoke Peacetime Military Coordination"
* Jesse C. Johnson
* 7/31/21

* Set Path and Open Data

	set more off
	*cd "E:\Jesse's Documents\Alliance Coordination\replication\JohnsonIIrep\"
	*use "JohnsonIIrep.dta", clear

* Distrubution of Peacetime Coordination

	tab peacecoord
	
* Table 2

	ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

* Substantive Effects and Figures (install Clarify)

* Figure 1

	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

		setx mean
		setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=0
		local b=1
		while `a'<=1 {
			replace xaxis=`a' in `b'
			setx cwin `a'
			quietly simqi, prval(0) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+.05
			local b=`b'+1
			}
		
	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Relative Capabilities ,  size(large))
		xlabel(0 .25 .50 .75 1,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))		
		ytitle("Probability of Low Coordination" ,  size(large))
		title("Low",  size(huge))
		lcolor("black")
		scheme(s1mono);
								
	# delimit cr

	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis

	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

	setx mean 
	setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=0
		local b=1
		while `a'<=1 {
			replace xaxis=`a' in `b'
			setx cwin `a'
			quietly simqi, prval(1) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+.05
			local b=`b'+1
			}
	
	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Relative Capabilities ,  size(large))
		xlabel(0 .25 .50 .75 1,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))		
		ytitle("Probability of Moderate Coordination" ,  size(large))
		title(Moderate,  size(huge))
		lcolor("black")
		scheme(s1mono);
								
	# delimit cr

	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis	
	
	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

	setx mean
	setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=0
		local b=1
		while `a'<=1 {
			replace xaxis=`a' in `b'
			setx cwin `a'
			quietly simqi, prval(2) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+.05
			local b=`b'+1
			}
		
	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Relative Capabilities ,  size(large))
		xlabel(0 .25 .50 .75 1 ,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))		
		ytitle("Probability of High Coordination" ,  size(large))
		title(High,  size(huge))
		lcolor("black")
		scheme(s1mono);
								
	# delimit cr

	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis
	
* Figure 2

	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

	setx mean 
	setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=1
		local b=1
		while `a'<=6 {
			replace xaxis=`a' in `b'
			setx salchal `a'
			quietly simqi, prval(0) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+1
			local b=`b'+1
			}

	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Salience,  size(large))
		xlabel(1 2 3 4 5 6,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))		
		ytitle("Probability of Low Coordination",  size(large))
		title(Low,  size(huge))
		lcolor("black")
		scheme(s1mono);
								
	# delimit cr
	
	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis
	
	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

	setx mean 
	setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=1
		local b=1
		while `a'<=6 {
			replace xaxis=`a' in `b'
			setx salchal `a'
			quietly simqi, prval(1) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+1
			local b=`b'+1
			}

	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Salience,  size(large))
		xlabel(1 2 3 4 5 6,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))				
		ytitle("Probability of Moderate Coordination",  size(large))
		title(Moderate,  size(huge))
		lcolor("black")
		scheme(s1mono);							

	# delimit cr

	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis
	
	estsimp ologit peacecoord cwin salchal saltgt allied threat similarity dem asym

	setx mean 
	setx dem 0 allied 1 asym 1

		generate xaxis=.
		gen simshigh=.
		gen simslow=.
		gen simspoint=.
		local a=1
		local b=1
		while `a'<=6 {
			replace xaxis=`a' in `b'
			setx salchal `a'
			quietly simqi, prval(2) genpr(pi1)
			_pctile pi1, p(2.5,50,97.5)
			replace simslow=r(r1) in `b'
			replace simspoint=r(r2) in `b'
			replace simshigh=r(r3) in `b'
			drop pi1
			local a=`a'+1
			local b=`b'+1
			}
		
	# delimit ;
	set more off;

	sort xaxis;						

	twoway rarea simslow simshigh xaxis, color("gs11") lw(none)
		||line simspoint xaxis,
		legend(off)
		xtitle(Challenger's Salience,  size(large))
		xlabel(1 2 3 4 5 6,  labsize(large))
		ylabel(0 .1 .2 .3 .4 .5 .6 .7,  labsize(large))				
		ytitle("Probability of High Coordination",  size(large))
		title(High,  size(huge))
		lcolor("black")
		scheme(s1mono);							

	# delimit cr

	drop b1-b10
	drop simshigh* simslow* simspoint* xaxis

********************************************************************************

* Online Appendix
	
* Figure A1

	hist peacecoord, start(0) discrete frequency  scheme(s1mono) xtitle(Level of Peacetime Coordination) xlabel(0 "Low" 1 "Moderate" 2 "High") plotregion(margin(l-20))

* Figure A2

	hist cwin, frequency bin(75) scheme(s1mono) xtitle(Challenger's Relative Capabilities)

* Figure A3

	hist salchal, discrete frequency  scheme(s1mono) xtitle(Challenger's Salience) xlabel(1 2 3 4 5 6) plotregion(margin(l-10))

* Table A1

	ologit peacecoord cwin saltgt allied threat similarity dem asym

* Table A2

	ologit peacecoord salchal saltgt allied threat similarity dem asym

* Table A3

	ologit peacecoord cwin salchal saltgt allied threat similarity dem asym if big==0
	
* Table A4

	ologit peacecoord cwin salchal saltgt allied threat similarity dem asym if frequent==0
	
* Table A5

	ologit peacecoord cwin salchal saltgt allied threat similarity dem asym if influential==0
		
* Table A6

	ologit peacecoord cwin salchal saltgt threat similarity dem asym if allied==0
		
* Table A7 (install gologit2)

	gologit2 peacecoord cwin salchal saltgt allied threat similarity dem asym, auto
